home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_500 / wiconify / wiconsetter.lzh / wIdentify / wHandler.c < prev    next >
C/C++ Source or Header  |  1991-04-19  |  4KB  |  168 lines

  1. /*
  2.  *  WIDENTIFY   A companion utility to wIconSetter and wIconify that allows
  3.  *              you to determine the commands necessary to properly identify
  4.  *              a window or screen in the wIconSetter initialization file.
  5.  *
  6.  *  wHandler.c     SetFunction routines for wIdentify.
  7.  *
  8.  *  Copyright 1990 by Davide P. Cervone, all rights reserved.
  9.  *  You may use this code, provided this copyright notice is kept intact.
  10.  */
  11.  
  12. #include "wIdentify.h"
  13.  
  14.  
  15. /*
  16.  *  StripPath()
  17.  *
  18.  *  Start at the end of the string
  19.  *  While there are more characters to look at,
  20.  *    Get the preceding character
  21.  *    If it is '/' or ':' cancel the loop, otherwise back up a character
  22.  *  Clip the length of the name, if necessary
  23.  *  Terminate the Name string
  24.  *  Copy the name portion of the string into the Name buffer
  25.  */
  26.  
  27. static void StripPath(Name,s,len)
  28. char Name[MAXNAME];
  29. char *s;
  30. short len;
  31. {
  32.    short i = 0;
  33.    char c;
  34.  
  35.    s += len;
  36.    while (len)
  37.    {
  38.       c = *(s-1);
  39.       if (c == '/' || c == ':') len = 0;
  40.          else len--, s--, i++;
  41.    }
  42.    if (i >= MAXNAME) i = MAXNAME-1;
  43.    Name[i] = 0;
  44.    while (i--) Name[i] = s[i];
  45. }
  46.  
  47.  
  48. /*
  49.  *  GetProgramName()
  50.  *
  51.  *  If we have a task to look at,
  52.  *    If the task is a process
  53.  *      If the process has a task number and a CLI structure
  54.  *        Get the CLI structure, and use its current command name and length
  55.  *    If we haven't found the name yet,
  56.  *      Get the name from the task structure, and find its length
  57.  *    Strip the path portion off the name
  58.  *  Otherwise clear the name buffer
  59.  */
  60.  
  61. void GetProgramName(Name,theTask)
  62. char Name[MAXNAME];
  63. struct Process *theTask;
  64. {
  65.    struct CommandLineInterface *theCLI;
  66.    char *s = NULL;
  67.    short len;
  68.  
  69.    if (theTask)
  70.    {
  71.       if (theTask->pr_Task.tc_Node.ln_Type == NT_PROCESS)
  72.       {
  73.          if (theTask->pr_TaskNum && theTask->pr_CLI)
  74.          {
  75.             theCLI = (struct CommandLineInterface *)BADDR(theTask->pr_CLI);
  76.             if (theCLI->cli_CommandName)
  77.                s = (char *)(BADDR(theCLI->cli_CommandName)), len = *s++;
  78.          }
  79.       }
  80.       if (s == NULL)
  81.       {
  82.          s = theTask->pr_Task.tc_Node.ln_Name;
  83.          len = strlen(s);
  84.       }
  85.       StripPath(Name,s,len);
  86.    } else {
  87.       Name[0] = 0;
  88.    }
  89. }
  90.  
  91.  
  92. /*
  93.  *  HandleWindow()
  94.  *
  95.  *  Get a temporary reply port
  96.  *  If successful,
  97.  *    Get the current task's program name
  98.  *    Save the screen and window pointers and the program name in the message
  99.  *    Set up the reply port for the message, and send the message
  100.  *    Wait for it to be returned, and get the reply
  101.  *    Delete the temporary port
  102.  */
  103.  
  104. static void HandleWindow(theScreen,theWindow)
  105. struct Screen *theScreen;
  106. struct Window *theWindow;
  107. {
  108.    char Program[MAXNAME];
  109.    struct MsgPort *thePort;
  110.    struct IdMessage theMessage;
  111.  
  112.    thePort = CreatePort(0,0);
  113.    if (thePort)
  114.    {
  115.       GetProgramName(Program,FindTask(NULL));
  116.       theMessage.Screen = theScreen;
  117.       theMessage.Window = theWindow;
  118.       theMessage.Program = &Program[0];
  119.       theMessage.Message.mn_ReplyPort = thePort;
  120.       theMessage.Message.mn_Length = sizeof(struct IdMessage);
  121.       PutMsg(IdPort,&theMessage);
  122.       WaitPort(thePort); GetMsg(thePort);
  123.       DeletePort(thePort);
  124.    }
  125. }
  126.  
  127.  
  128. /*
  129.  *  cOpenWindow()
  130.  *
  131.  *  If we actually got a window, print its information.
  132.  */
  133.  
  134. void cOpenWindow(theWindow)
  135. struct Window *theWindow;
  136. {
  137.    if (theWindow) HandleWindow(theWindow->WScreen,theWindow);
  138. }
  139.  
  140.  
  141. /*
  142.  *  cSetWindowTitles()
  143.  *
  144.  *  If a window is specified and its title is changing,
  145.  *    print its information.
  146.  */
  147.  
  148. void cSetWindowTitles(theWindow,wTitle,sTitle)
  149. struct Window *theWindow;
  150. UBYTE *wTitle,*sTitle;
  151. {
  152.    if (theWindow && wTitle != (UBYTE *)-ONE)
  153.       HandleWindow(theWindow->WScreen,theWindow);
  154. }
  155.  
  156.  
  157. /*
  158.  *  cOpenScreen()
  159.  *
  160.  *  If a screen was openned, print its information as a screen.
  161.  */
  162.  
  163. void cOpenScreen(theScreen)
  164. struct Screen *theScreen;
  165. {
  166.    if (theScreen) HandleWindow(theScreen,SCREENICON);
  167. }
  168.